/*
* INSANE - Interactive Structural Analysis Environment
*
* Copyright (C) 2003-2005
* Universidade Federal de Minas Gerais
* Escola de Engenharia
* Departamento de Engenharia de Estruturas
* 
* Author's email :    insane@dees.ufmg.br
* Author's website :  http://www.dees.ufmg.br/insane
* 
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or any later version.
* 
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
* 
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/
package br.ufmg.dees.insane.model.disc.analysismodel;

import br.ufmg.dees.insane.crossSection.CrossSection;
import br.ufmg.dees.insane.materialMedia.material.Material;
import br.ufmg.dees.insane.model.disc.element.FrameElement;
import br.ufmg.dees.insane.model.disc.fem.FemModel;
import br.ufmg.dees.insane.model.disc.pointforce.PointForce;
import br.ufmg.dees.insane.util.IMatrix;
import br.ufmg.dees.insane.util.IVector;

/**
*A class representing an analysis model.
*
*@author Fonseca, Flavio & Lucas, Marcelo & Pitangueira, Roque
*@version 1.0
*@since September 2003
*/

public abstract class AnalysisModel implements java.io.Serializable {
	
	/**The label of this AnalysisModel. */
	protected String type;
	
	/**The number of degrees of freedom of each node for this AnalysisModel */
	protected int ndf;
	
	/**The dominion (2D or 3D) of this AnalysisModel. */
	protected int dominion;
	
	/**The valid equations of this AnalysisModel.<br>
	*They are related to the displacements stored in this order: <i>Dx, Dy, Dz, Rx, Ry, Rz</i>.
	*/
	protected boolean[] validEquations = new boolean[6];
	
//********************************************************************************

	/** Returns the B matrix related to analysis model type 
	*@param dl The matrix containing local derivates of shape functions.
	*@param n The vector containing shape functions in natural coordinates.
	*@param cN The matrix containing nodal coordinates in cartesian system.
	*@return The matrix B 
	*/
	public abstract IMatrix mountBMatrix(IMatrix dl, IVector n, IMatrix cN);
	
	/** Return the inverse of jacobian matrix.
	*@param a The jacobian matrix.
	*@return the inverse of jacobian matrix.
	*/
	protected abstract IMatrix invertJacobian(IMatrix a);
	
	/** Mounts the matrix of the material properties for the analysis model type.
	*@param a The matrix of material properties.
	*@return matrix D related to analysis model type 
	*/
	public abstract IMatrix mountDMatrix(double[][] a);
	
	/** Mounts the shape function matrix accordingly to the AnalysisModel type with the values of two IVectors.<br>
	*The first IVector must contain the shape functions values which will be put in the upper part of the matrix.<br>
	*The second IVector must contain the shape functions values which will be put in the lower part of the matrix (related to the derivated shape functions).
	*@param n1 A IVector containing the shape functions values which will be put in the upper part of the matrix.
	*@param n2 A IVector containing the shape functions values which will be put in the upper part of the matrix.
	*@return The shape function matrix accordingly to the AnalysisModel type.
	*/
	public abstract IMatrix mountMatrixN(IVector n1, IVector n2);
	
	/** Mounts the shape function matrix accordingly to the AnalysisModel type with the values of one IVector.<br>
	*The IVector must contain the shape functions values which will be put in the upper part of the matrix.<br>
	*The value zero will be put in the lower part of the matrix (related to the derivated shape functions).
	*@param n1 A IVector containing the shape functions values which will be put in the upper part of the matrix.
	*@return The shape function matrix accordingly to the AnalysisModel type.
	*/
	public abstract IMatrix mountMatrixN(IVector n1);
	
	/** Prints in the screen a table with the valid nodal displacements for the AnalysisModel type.
	*@param femModel The FemModel which contains the data to be printed.
	*/
	public abstract void printDisplacements(FemModel femModel);
	
	/** Prints in the screen a table with the valid support reactions for the AnalysisModel type.
	*@param femModel The Model which contains the data to be printed.
	*/
	public abstract void printReactions(FemModel femModel);
	
	/** Prints in the screen a table with the valid actions at elements' extremities for the AnalysisModel type.
	*@param femModel The FemModel which contains the data to be printed.
	*/
	public abstract void printActionsAtExtremities(FemModel femModel);
	
	/** Return the number of active stresses according to this Analysis model type.*/
	public abstract int getNumberOfActiveStress();
	
	/** Return the number of active strains according to this Analysis model type.*/
	public abstract int getNumberOfActiveStrains();
	
	/** Return the non zero stresses that perform in one point. 
	*@param a The IVector containing stresses of the point.
	*@param b The Material that will be used to obtain material properties.
	*@return stressVector The IVector according this Analysis Model.
	*/
	public abstract IVector getStressVector(IVector a, Material b);
	
	/** Return the non zero strains that perform in one point. 
	*@param a The IVector containing strains of the point.
	*@param b The Material that will be used to obtain material properties.
	*@return strainVector The IVector according this Analysis Model.
	*/
	public abstract IVector getStrainVector(IVector a, Material b);
	
	/** Return the String representing the non zero stresses of this Analysis Model.
	*@return The string containing the label of non zero stresses of this Analysis Model.
	*/
	public abstract String getStressLabels();
	
	/** Return the string representing the non zero strains of thisAnalysis Model.
	*@return The string containing the label of non zero strains of this Analysis Model.
	*/
	public abstract String getStrainLabels();
	
	/** Return the integration factor according to analysis model type.
	*@param n The vector containing the shape functions.
	*@param cN The matrix containing the nodal coordinates in cartesian system.
	*@return The integration factor according to analysis model type.
	*/
	public abstract double getStiffnessFactor(IVector n, IMatrix cN);
	
	/** Return the jacobian matrix.
	*@param dl The matrix of local derivates.
	*@param cN The matrix of nodal coordinates.
	*@return dl * cN The jacobian matrix.
	*/
	public abstract IMatrix getJacobian(IMatrix dl, IMatrix cN);
	
//********************************************************************************
	
	/** Returns the type of this AnalysisModel.
	*@return The type of this AnalysisModel.
	*/
	public String getType() {
		return(type);
	}
	
	/** Sets the type of this AnalysisModel.
	*@param a The type of this AnalysisModel.
	*/
	public void setType(String a) {
		type = a;
	}
	
//********************************************************************************
	
	/** Returns the number of degrees of freedom of this AnalysisModel.
	*@return The number of degrees of freedom of this AnalysisModel.
	*/
	public int getNdf() {
		return(ndf);
	}
	
	/** Sets the number of degrees of freedom of this AnalysisModel.
	*@param a The number of degrees of freedom of this AnalysisModel.
	*/
	public void setNdf(int a) {
		ndf = a;
	}
	
//********************************************************************************
	
	/** Returns the valid equation of this AnalysisModel in the specified position.
	*@return The valid equation of this AnalysisModel in the specified position
	*/
	public boolean getValidEquation(int a) {
		return(validEquations[a]);
	}
	
	/** Sets the valid equation of this AnalysisModel in the specified position.
	*@param a The position of the valid equation.
	*@param b The valid equation of this AnalysisModel in the specified position
	*/
	public void setValidEquation(int a, boolean b) {
		validEquations[a] = b;
	}
	
//********************************************************************************
	
	/** Returns the dominion of this analysis model.
	*@return The dominion of this analysis model.
	*/
	public int getDominion() {
		return dominion;
	}
	
	/** Sets the dominion of this analysis model.
	*@param a The dominion of this analysis model (if plane, dominion = 2; if spatial, dominion = 3).
	*/
	public void setDominion(int a) {
		dominion = a;
	}
	
//********************************************************************************
	
	/**Return the vector with only just existing forces according to this Analysis Model.
	*@param pf The point force containg the six possible forces.
	*@return redForce The IVector with only just existing forces according to this Analysis Model.
	*/
	public IVector getReducedForceVector(PointForce pf)	{
		IVector redForce = new IVector(this.getNdf());
		for(int i = 0; i < (this.getNdf()); i++){
			int j = 0;
			if(this.getValidEquation(i)) {
				redForce.setElement(j, pf.getForce(i));
				j++;
			}
		}
		return redForce;
	}
	
    /** Returns the B matrix related to analysis model type 
     *@param dg The vector containing global derivates of shape functions.
     *@return The matrix B 
     */
     public IMatrix mountBMatrix(IVector dg) { return null; }

     
     /** Returns the B matrix related to analysis model type 
      *@param dg The vector containing global derivates of shape functions.
      *@return The matrix B 
      */
      public IMatrix mountDMatrix(double[][] mp, CrossSection cs) { return null;}
      
      public abstract IMatrix transformationMatrix(FrameElement elm);
      
//********************************************************************************
}
